import React, { useRef, useState, useEffect } from 'react';
import { connect } from 'umi';
import { Button, } from 'antd';
import SelectTagFrom from '@/components/SelectTagForm';
const OverviewTagComponents = (props) => {
  const { dispatch, handleCallback, e, record } = props;
  const [tagVisible, setTagVisible] = useState(false);
  const onSetList = (detail = [],) => {
    const { id, } = tagVisible
    dispatch({
      type: 'user/fakeEditUserTag',
      payload: {
        id,
        tagIdList: detail.map(item => {
          return item.id
        })
      },
      callback: () => {
        setTagVisible(false)
        handleCallback();
      },
    });
  }

  return <>
    <Button
      type="link"
      onClick={() => {
        dispatch({
          type: 'subscriber/fetchUserDetail',
          payload: {
            organizationUserId: record.id,
          },
          callback: (e) => {
            const { tagIds } = e;
            setTagVisible({ handleCallback: handleCallback, show: true, id: record.id, detail: tagIds.split(',').map(item => { return { id: Number(item) } }) })
          },
        });
      }}
    >
      {e ? e : <div style={{ color: 'red' }}>设置标签</div>}
    </Button>
    <SelectTagFrom
      onSetList={onSetList}
      visible={tagVisible}
      onClose={() => setTagVisible(false)}
    ></SelectTagFrom>
  </>
}

export default connect(({ }) => ({

}))(OverviewTagComponents);
